#ifndef PINYIN_COM_H
#define PINYIN_COM_H

#include <gtk/gtk.h>
#include <stdbool.h>

#define MAX_PINYIN_LEN 64
#define MAX_CANDIDATES 64
#define CANDIDATES_PER_PAGE 10
#define MAX_TEXT_LEN 1024

typedef enum {
    MODE_ENGLISH,
    MODE_CHINESE
} InputMode;

typedef enum {
    LAYOUT_LETTERS,
    LAYOUT_NUMBERS,
    LAYOUT_SYMBOLS
} KeyboardLayout;

typedef struct {
    char pinyin[MAX_PINYIN_LEN];
    char hanzi[MAX_CANDIDATES][4]; // 每个汉字最多3字节+1个结束符
    int count;
} PinyinMap;

typedef struct {
    InputMode mode;
    KeyboardLayout layout;
    char pinyin_buffer[MAX_PINYIN_LEN];
    int pinyin_len;
    char candidates[MAX_CANDIDATES][4];
    int candidate_count;
    int current_page;
    int total_pages;
    char text_buffer[MAX_TEXT_LEN];
    int text_len;
    int cursor_pos;
    
    // GUI组件
    GtkWidget *window;
    GtkWidget *entry;
    GtkWidget *keyboard_window;
    GtkWidget *pinyin_label;
    GtkWidget *candidate_buttons[CANDIDATES_PER_PAGE];
    GtkWidget *page_label;
    GtkWidget *mode_button;
    GtkWidget *layout_button;
    GtkWidget *candidate_box;
    GtkWidget *keyboard_container;
} InputContext;

// 拼音映射表
extern PinyinMap pinyin_map[];
extern const int pinyin_map_size;

// 函数声明
void init_input_context(InputContext *ctx);
void create_main_window(InputContext *ctx);
void create_keyboard_window(InputContext *ctx);
void update_keyboard_layout(InputContext *ctx);

#endif // PINYIN_COM_H